package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author SunSun
 * @date 2021/10/28
 */
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 查看评论
     * @param page
     * @param pagesize
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity  findComments(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                        String movementId){
        PageResult pr=commentService.findComments(page,pagesize,movementId);
        return ResponseEntity.ok(pr);

    }

    /**
     * 发布评论
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map){

        String comment = (String) map.get("comment");
        String movementId = (String) map.get("movementId");
        commentService.saveComment(comment,movementId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String commentId){
        Integer likecomment = commentService.commentlike(commentId);
        return ResponseEntity.ok(likecomment);
    }

    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String commentId){
        Integer dislikecomment = commentService.commentdislike(commentId);
        return ResponseEntity.ok(dislikecomment);
    }
}
